package com.leetcode.题库;

import java.util.Arrays;

/**
 * @author 覃国强
 * @date 2022-03-12 20:14
 */
public class 题库_1991_找到数组的中间位置 {

  static
  class Solution {
    public int findMiddleIndex(int[] nums) {
      int sum = Arrays.stream(nums).sum();
      int prefix = 0;
      for (int i = 0; i < nums.length; ++i) {
        if (sum - prefix - nums[i] == prefix) {
          return i;
        }
        prefix += nums[i];
      }
      return -1;
    }
  }

}
